1804A - Lame King - CodeForces Solution


greedy math

Please click on ads to support us..

C++ Code:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <stack>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
//================================================================
// يا رب
/*بسم الله الرحمن الرحيم
اللهم صلي علي سيدنا محمد
 */
/*
  سَبِّحِ اسْمَ رَبِّكَ الأَعْلَى
  الَّذِي خَلَقَ فَسَوَّى
  وَالَّذِي قَدَّرَ فَهَدَ
  وَالَّذِي أَخْرَجَ الْمَرْعَى
  فَجَعَلَهُ غُثَاءً أَحْوَى
  سَنُقْرِؤُكَ فَلا تَنسَى
  إِلاَّ مَا شَاء اللَّهُ إِنَّهُ يَعْلَمُ الْجَهْرَ وَمَا يَخْفَى
  وَنُيَسِّرُكَ لِلْيُسْرَى
فَذَكِّرْ إِن نَّفَعَتِ الذِّكْرَى
*/
//================================================================
//OTHERS
#define Ones(n) __builtin_popcount(n)
#define _Nader cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);
#define END return 0;
#define e '\n'
#define inarr(n, arr) for(int ax = 0; ax<(n); ax++)cin>>(arr)[ax];
#define E '\n'
#define yes cout<<"YES"<<e;
#define no cout<<"NO"<<e;
#define YES cout<<"YES"<<e;
#define NO cout<<"NO"<<e;
#define GO continue;
#define ll long long
#define lll __int128_t
#define ld long double
//================================================================
// pairs
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
#define mp make_pair
#define f first
#define s second
//================================================================
// vectors
#define tcT template <class T
tcT > using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<ld>;
using vs = V<string>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
using mll = map<ll,ll>;
using pll = pair<ll,ll>;

//================================================================
//LOOPS
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define f(i, a, b)  for(int i = a; i < b; i++)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define each(a, x) for (auto &a : x)
//================================================================
//OPERATIONS
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define rall(x) x.rbegin(), x.rend()

#define pb push_back
#define PB push_back
#define eb emplace_back
#define SZ(x)  (x.size())
//================================================================
//CONSTANTS
const int OO = 0x3f3f3f3f;
const ll LOO = 0x3f3f3f3f3f3f3f3f;
const unsigned ll mod = 1000000007;
const ll MOD = 998244353;
const int N = 3e5+5;
const long double EPS = 1e-8;
//const ll N = 1'000'000'000'000L;
ll dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
ll dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};
// string strpi = "3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067";

//================================================================
void _GOAT_() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
//==================================================================
//Reminders
//partial_sum(v.begin(), v.end(), v.begin());
//     priority_queue<ll> pq;  reversed - sorted (lg n)
//    priority_queue<ll,vl,greater<ll>> pq(all(a)); only sorted

//struct X{
//    ll l,r,c;
//};
//==================================================================

void testCase(ll tc) {
    ll a,b;
    cin>>a>>b;
    ll ans = (abs(a)+abs(b))+max(abs(abs(a)-abs(b))-1,0LL);
    cout << ans <<e;

}


int main() {
    _Nader
    ll tt = 1;
  cin >> tt;
    ll tc = 0;
    while (tt--) {
        testCase(++tc);
    }
    END
}


Comments

Submit
0 Comments
More Questions

1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs
1455B - Jumps
1225C - p-binary
1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game
1382A - Common Subsequence
1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket